<?php 

class M_main extends CI_Model{

	function M_main(){
		parent::__construct();
	}

	function check_license($opt){
		if($opt=="DEMO"){
			$_SESSION[SESSION_LICENSE] = 'DEMO';
			$sql="SELECT * FROM tbl_s_info 
					WHERE info_nama='DEMO VERSION'";
			$result=$this->db->query($sql);
			if($result->num_rows()){
				return true;
			}else{
				return false;
			}
		}else{
			$_SESSION[SESSION_LICENSE] = 'FULL';
			return true;
		}
	}
	
	function get_menus($opt){
		if($opt=="open"){
			if($_SESSION[SESSION_USERID]==='Super Admin')
				$sql="select * from tbl_s_menus where menu_aktif='Y' order by menu_position asc";
			else
				$sql="select * from vu_s_menus 
					where group_id='".$_SESSION[SESSION_GROUPID]."' 
					and menu_aktif='Y' order by menu_position asc ";
			
		}else{
			$sql="select * from tbl_s_menus where (menu_kode='FILE' OR menu_kode='HELP') 
					AND menu_aktif='Y' order by menu_position asc";
		}
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	function get_menus_parent($opt){
		if($opt=="open"){
			if($_SESSION[SESSION_USERID]==='Super Admin')
				$sql="select * from tbl_s_menus where menu_parent=0 and menu_id!=1 and menu_aktif='Y' order by menu_position asc";
			else
				$sql="select * from vu_s_menus
					where group_id='".$_SESSION[SESSION_GROUPID]."'
					and menu_parent=0 and menu_id!=1 and menu_aktif='Y' order by menu_position asc ";
				
		}else{
			$sql="select * from tbl_s_menus where (menu_kode='FILE' OR menu_kode='HELP')
					AND menu_aktif='Y' order by menu_position asc";
		}
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	function get_menus_child($parent_id){
		if($_SESSION[SESSION_USERID]==='Super Admin')
			$sql="select * from tbl_s_menus where menu_parent=".$parent_id." and menu_aktif='Y' order by menu_position asc";
		else
			$sql="select * from vu_s_menus
				where group_id='".$_SESSION[SESSION_GROUPID]."'
				and menu_parent=".$parent_id." and menu_aktif='Y' order by menu_position asc ";
	
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	function get_setting_menus($opt){
		if($opt=="open"){
			if($_SESSION[SESSION_USERID]==='Super Admin')
				$sql="select * from tbl_s_menus where menu_parent=1
				AND menu_aktif='Y' order by menu_position asc";
			else
				$sql="select * from vu_s_menus
					where group_id='".$_SESSION[SESSION_GROUPID]."'
					and menu_parent=1  AND menu_aktif='Y' order by menu_position asc ";
				
		}else{
			$sql="select * from tbl_s_menus where (menu_kode='FILE' OR menu_kode='HELP')
					AND menu_parent=1  AND menu_aktif='Y' order by menu_position asc";
		}
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	function get_background(){
		$background="";
		$sql="select info_background from tbl_s_info";
		$query=$this->db->query($sql);
		if($query->num_rows()){
			$rs=$query->row();
			$background=$rs->info_background;
		}
		return $background;
	}	
	
	
	function get_sub_menus($opt){
		if($opt=="open"){
			if($_SESSION[SESSION_USERID]==='Super Admin')
				$sql="select * from tbl_s_menus where menu_parent<>0  
				AND menu_aktif='Y' order by menu_parent,menu_position asc";
			else
				$sql="select * from vu_s_menus 
				where group_id='".$_SESSION[SESSION_GROUPID]."' 
				and menu_parent<>0 AND menu_aktif='Y' order by menu_parent,menu_position asc ";
			
		}else{
			$sql="SELECT
						A .*
					FROM
						tbl_s_menus A LEFT JOIN tbl_s_menus B ON(A .menu_parent = B.menu_id)
					WHERE
						A .menu_parent <> 0
					AND A .menu_aktif = 'Y'
					AND ( B.menu_kode='FILE' OR B.menu_kode='HELP') 
					ORDER BY
						A .menu_parent,
						A .menu_position ASC";
		}
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	function get_shortcuts($opt){
		if($opt=="open"){
			if($_SESSION[SESSION_USERID]==='Super Admin')
				$sql="select * from tbl_s_menus where menu_parent<>0 
					and menu_leftpanel='Y' AND menu_aktif='Y' order by menu_parent,menu_position asc";
			else
				$sql="select * from vu_s_menus 
					where menu_parent<>0 and group_id='".$_SESSION[SESSION_GROUPID]."' 
					and menu_leftpanel='Y' AND menu_aktif='Y' order by menu_parent,menu_position asc ";
		}else{
			$sql="SELECT
						A .*
					FROM
						tbl_s_menus A LEFT JOIN tbl_s_menus B ON(A .menu_parent = B.menu_id)
					WHERE
						A .menu_parent <> 0
					AND A .menu_aktif = 'Y'
					AND ( B.menu_kode='FILE' OR B.menu_kode='HELP') 
					ORDER BY
						A .menu_parent,
						A .menu_position ASC";
		}
		
		$query=$this->db->query($sql);
		$rs=$query->result_array();
		return $rs;
	}
	
	
}
?>